Title: Alphabetical Lore
Author: SilentEnigma
Version: 1.1
Release Date: 2023-11-05
Applies to: Final Fantasy III (v1.0) (U)

Archive Contents
-------------------------------

  readme.txt         = this file

  LoreAZ_H.ips       = patch for headered ROMs
  LoreAZ_H_Anti.ips  = anti-patch for headered ROMs

  LoreAZ_NH.ips      = patch for unheadered ROMs
  LoreAZ_NH_Anti.ips = anti-patch for unheadered ROMs


ROM Addresses
-------------------------------
  C2/5564 - C2/5586, C2/FBD0 - C2/FBD3
  C3/520F - C3/5213, C3/5290 - C3/5291, C3/52A0 - C3/52A1


Free Space Used
-------------------------------
  C2/669D - C2/66A3, C2/67A8 - C2/67BF (31 bytes)
  C3/FA4C - C3/FA74                    (41 bytes)


TABLE OF CONTENTS
-------------------------------

0. Description
1. Relevant Offsets & Disassembly
2. Credits
3. Revision History
4. Legal

________________________________________________________________________________

  0. DESCRIPTION
________________________________________________________________________________


This patch alphabetically sorts the Lore list in FF3us for the SNES.
It uses roughly the same implementation as "Alphabetical Rage" by Assassin.


FF3us Lore Unsorted
-------------------------------
00 Condemned
01 Roulette
02 CleanSweep
03 Aqua Rake
04 Aero
05 Blow Fish
06 Big Guard
07 Revenge
08 Pearl Wind
09 L.5 Doom
0A L.4 Flare
0B L.3 Muddle
0C Reflect???
0D L? Pearl
0E Step Mine
0F ForceField
10 Dischord
11 Sour Mouth
12 Pep Up
13 Rippler
14 Stone
15 Quasar
16 GrandTrain
17 Exploder


FF3us Lore Sorted
-------------------------------
04 Aero
03 Aqua Rake
06 Big Guard
05 Blow Fish
02 CleanSweep
00 Condemned
10 Dischord
17 Exploder
0F ForceField
16 GrandTrain
0B L.3 Muddle
0A L.4 Flare
09 L.5 Doom
0D L? Pearl
08 Pearl Wind
12 Pep Up
15 Quasar
0C Reflect???
07 Revenge
13 Rippler
01 Roulette
11 Sour Mouth
0E Step Mine
14 Stone

________________________________________________________________________________

  1. RELEVANT OFFSETS & DISASSEMBLY
________________________________________________________________________________


Sorting Map
-------------------------------

New Data:
C2/67A8: 04 03 06 05 02 00 10 17
C2/67B0: 0F 16 0B 0A 09 0D 08 12 15 0C 07 13 01 11 0E 14


Field Menu
-------------------------------

NOTE: Most of the modified subroutine C3/520F is moved to free space at C3/FA4C
to avoid a patching conflict with Novalia Spirit's "Rage Checklist"

Original:
 C3/520F: A2 89 9D   LDX #$9D89
 C3/5212: 8E 81 21   STX $2181
Modified:
 C3/520F: 4C 4C FA   JMP $FA4C      ; new subroutine C3/FA4C
 C3/5212: FF FF 21   ; need to leave C3/5214 for Rage Checklist compatibility

New Subroutine C3/FA4C:
 C3/FA4C: A2 89 9D    LDX #$9D89    ; moved original C3/520F
 C3/FA4F: 8E 81 21    STX $2181     ; moved original C3/5212
 C3/FA52: A6 00       LDX $00       ; list position
 C3/FA54: 7B          TDC
 C3/FA55: BF A8 67 C2 LDA $C267A8,X ; sorted lore ID
 C3/FA59: A8          TAY
 C3/FA5A: DA          PHX
 C3/FA5B: 18          CLC           ; next call depends on carry flag
 C3/FA5C: 22 D0 FB C2 JSL $C2FBD0   ; new subroutine C2/FBD0
 C3/FA60: 3C 29 1D    BIT $1D29,X   ; is this lore learned?
 C3/FA63: F0 03       BEQ $FA68     ; if not, branch
 C3/FA65: 98          TYA
 C3/FA66: 80 02       BRA $FA6A
 C3/FA68: A9 FF       LDA #$FF
 C3/FA6A: 8D 80 21    STA $2180
 C3/FA6D: FA          PLX
 C3/FA6E: E8          INX
 C3/FA6F: E0 18 00    CPX #$0018    ; number of lores
 C3/FA72: D0 E1       BNE $FA55
 C3/FA74: 60          RTS

Original
 C3/5290: A5 E5       LDA $E5       ; use list position as lore ID
Modified
 C3/5290: 48          PHA           ; A holds sorted lore ID
 C3/5291: EA          NOP

Original:
 C3/52A0: A5 E5       LDA $E5       ; use list position as lore ID
Modified:
 C3/52A0: 68          PLA           ; Recover sorted lore ID
 C3/52A1: EA          NOP

; New Subroutine C2/FBD0 [from Alphabetical Rage]
; Long access to subroutine C2/5217
C2/FBD0: 20 17 52     JSR $5217     ; X = A DIV 8, A = 1 SHL (A MOD 8)
C2/FBD3: 6B           RTL


Battle Menu
-------------------------------

Original:
 C2/5564: A0 17       LDY #$17      ; 24 possible Lores
 C2/5566: A2 02       LDX #$02
 C2/5568: 7B          TDC
 C2/5569: 38          SEC
 C2/556A: 6A          ROR
 C2/556B: 90 02       BCC $556F     ; have we looped a multiple of 8 times yet?
 C2/556D: 6A          ROR
 C2/556E: CA          DEX           ; if 9th/17th, set Bit 7 and repeat process
 C2/556F: 3C 29 1D    BIT $1D29,X   ; is this Lore learned?
 C2/5572: F0 10       BEQ $5584     ; branch if not
 C2/5574: EE 87 3A    INC $3A87     ; increment number of known Lores
 C2/5577: 48          PHA
 C2/5578: 98          TYA           ; Lore ID
 C2/5579: 69 37       ADC #$37      ; convert to position relative to Esper menu
 C2/557B: 99 0F 31    STA $310F,Y   ; save to "list of positions of each lore"
 C2/557E: 69 54       ADC #$54      ; convert to raw spell ID (Condemned=8B)
 C2/5580: 99 6A 30    STA $306A,Y   ; save spell ID to "list of known Lores"
 C2/5583: 68          PLA
 C2/5584: 88          DEY
 C2/5585: 10 E3       BPL $556A     ; iterate through Lores in reverse order
Modified:
 C2/5564: E8          INX           ; lore list position counter (init to 0)
 C2/5565: BF A8 67 C2 LDA $C267A8,X ; sorted lore ID
 C2/5569: A8          TAY
 C2/556A: DA          PHX           ; list position
 C2/556B: 18          CLC           ; next call depends on carry flag
 C2/556C: 20 17 52    JSR $5217     ; X = A DIV 8, A = 1 SHL (A MOD 8)
 C2/556F: 3C 29 1D    BIT $1D29,X   ; is this Lore learned?
 C2/5572: F0 0E       BEQ $5582     ; if not, branch
 C2/6674: AD 87 3A    LDA $3A87     ; number of known Lores
 C2/6677: 69 37       ADC #$37      ; list position relative to Esper menu
 C2/6679: 99 0F 31    STA $310F,Y   ; "list of positions of each Lore"
 C2/557C: EE 87 3A    INC $3A87     ; increment number of known Lores
 C2/557F: 20 9D 66    JSR $669D     ; new subroutine C2/669D
 C2/5582: FA          PLX           ; list position
 C2/5583: E0 17       CPX #$17      ; number of lores - 1
 C2/5585: D0 DD       BNE $5564     ; iterate over all lores

New Subroutine C2/669D:
 C2/669D: 98          TYA           ; sorted lore ID
 C2/669E: 69 8B       ADC #$8B      ; convert lore ID to raw spell ID
 C2/66A0: 99 6A 30    STA $306A,Y   ; moved original C2/5580
 C2/66A3: 60          RTS

________________________________________________________________________________

  2. CREDITS
________________________________________________________________________________


Assassin
 - "Alphabetical Rage" patch
 - Bank C2 Disassembly (w/ Terri Senshi)
http://assassin17.brinkster.net/patches.htm

Special Thanks:

  Imzogelmo, for his disassembly of bank C3
  http://www.angelfire.com/al2/imzogelmo/patches.html

________________________________________________________________________________

  3. REVISION HISTORY
________________________________________________________________________________


2022-08-29 : Version 1.0 released

2023-11-05 : Version 1.1 released
 - Fixed incorrect Lore listing on field menu when scrolling with L/R buttons

________________________________________________________________________________

  4. LEGAL
________________________________________________________________________________


Copyright (C) 2022, 2023 David R. Thompson (SilentEnigma).

The copyright holder ("author") permits the free use of the attributed work
referenced by this document exclusively for non-commercial purposes, provided
that the following conditions are met:
1. The author and all contributors credited in this readme document shall be
 given credit for their respective contributions wherever the attributed work is
 reused, redistributed, or modified.
2. This readme document shall accompany any of the files comprising the
 attributed work wherever they are redistributed in unmodified form.

The work(s) and file(s) distributed with this document are provided "AS-IS",
WITHOUT ANY WARRANTY. The author shall not be held responsible for any damages
related to the use of work(s) and file(s) distributed with this document.
